<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script language="JavaScript" type="text/javascript">

	var idExamine = $.getUrlVar("idExamine");

	$(document).ready(function() {

		$.jtable();

		$(".edit").click(function() {
			loadTextEditor();
		});
		
		$("#listSerAll").hide();
		$("#listMedAll").hide();

	});

	function updateDisease() {

		var $form = $("#frmDisease");
		var txtDisease = $form.find('textarea#txtDisease').val();
		$.ajax({
			type : "POST",
			url : "/GoodHealth-web/Doctor/exam.do?act=updateDisease&idExamine="
					+ idExamine + "&txtDisease=" + txtDisease,
			success : function(data) {
				$('#disease').html(data);
			}
		});
	}

	function addLabs(idLabInf) {

		$.ajax({
					type : "POST",
					dataType : "html",
					url : "/GoodHealth-web/Doctor/exam.do?act=addLabService&idLabServiceInfo="
							+ idLabInf + "&idExamine=" + idExamine,
					success : function(html) {
						$("#addSerResult"+idLabInf).html(html);
						$.jtable();
					}
				});
	}
	function addMeds(idMedInf) {

		var dose = $("#dose"+idMedInf).val();
		var quantity = $("#quantity"+idMedInf).val();

		$.ajax({
					type : "POST",
					dataType : "html",
					url : "/GoodHealth-web/Doctor/exam.do?act=addMedicine&idMedicineInfo="
							+ idMedInf + "&idExamine=" + idExamine+ "&dose=" + dose+ "&quantity=" + quantity,
					success : function(html) {
						$("#addMedResult"+idMedInf).html(html);
						$.jtable();
					}
				});
	}

	function delLabs(idLabDetail){
		$.ajax({
			type : "POST",
			dataType : "html",
			url : "/GoodHealth-web/Doctor/exam.do?act=delLab&idLabDetail="+idLabDetail,
			success : function(html) {
				loadAJAX("listSerbyId");
				$.jtable();
			}
		});
	}
	function delMeds(idMedicineDetail){
		$.ajax({
			type : "POST",
			dataType : "html",
			url : "/GoodHealth-web/Doctor/exam.do?act=delMed&idMedicineDetail="+idMedicineDetail,
			success : function(html) {
				loadAJAX("listMedbyId");
				$.jtable();
			}
		});
	}
	
	function loadTextEditor() {
		$("#disease")
				.html(
						"<form id='frmDisease' method='post'><textarea id='txtDisease'></textarea><br><input type='button' onclick='updateDisease()' value=Update> <input type=button value=Cancel></form>");
	}
	function LoadList(div) {
		$("#"+div).show("slow");
		loadAJAX(div);
	}


	function loadAJAX(source) {
		var stringUrl = "";
		var dataDiv = "";
		if (source == "listSerAll") {
			stringUrl = "/GoodHealth-web/Doctor/doctor.do?view=listLabs";
			dataDiv = "#listSerAlltb";
		} else if (source == "listMedAll") {
			stringUrl = "/GoodHealth-web/Doctor/doctor.do?view=listMeds";
			dataDiv = "#listMedAlltb";
		} else if(source == "listSerbyId"){
			stringUrl = "/GoodHealth-web/Doctor/doctor.do?view=listLabs&idExamine="
				+ idExamine;
		dataDiv = "#listSerbyID";
	}else if(source == "listMedbyId"){
		stringUrl = "/GoodHealth-web/Doctor/doctor.do?view=listMeds&idExamine="
			+ idExamine;
	dataDiv = "#listMedbyID";
}

		$.ajax({
			type : "POST",
			dataType : "html",
			url : stringUrl,
			success : function(html) {

				$(dataDiv).html(html);
				$.jtable();
			}
		});
	}
	function closeDiv(div) {
		if (div == "listSerAll")
		loadAJAX("listSerbyId");
		else if(div == "listMedAll")
			loadAJAX("listMedbyId");
		
		$("#"+div).css("visibility", "visible").hide("slow");

	}
</script>



<%
	if (request.getParameter("view") == null
			|| request.getParameter("view").equals("noneexamine")
			|| request.getParameter("view").equals("examineed")) {
%>
<div id=main>
	<table class='jtable'>
		<thead>
			<tr>
				<th>Examine ID</th>
				<th>Patient name</th>
				<th>Appointment day</th>
				<th>Examine Day</th>

			</tr>
		</thead>
		<tbody>


			<c:forEach var="item" items="${requestScope.listExam}">

				<tr>
					<td>${item.idExamine}</td>
					<td><a
						href="/GoodHealth-web/Doctor/doctor.do?view=examdetail&idExamine=${item.idExamine}">${item.patientDetail.firstName}
							${item.patientDetail.lastName}</a></td>
					<td>${item.appointmentDay}</td>
					<td>${item.examineDay}</td>
				</tr>

			</c:forEach>

		</tbody>
	</table>
</div>
<%
	} else {
%>


<div id="main">
<h2>Patient Informations</h2>
	<table>
		<tr>
			<td><img src="" width=100 height=150></td>
			<td style="padding-left: 20px; vertical-align: top left">
				<table>
					<tr>
						<td>PatientID</td>
						<td>:</td>
						<td>${requestScope.PatientDetail.idPatientDetail}</td>
					</tr>
					<tr>
						<td>Name</td>
						<td>:</td>
						<td><b>${requestScope.PatientDetail.firstName}
								${requestScope.PatientDetail.lastName}</b></td>
					</tr>
					<tr>
						<td>Examine Day</td>
						<td>:</td>
						<td>${requestScope.Exam.examineDay}</td>
					</tr>
					<tr>
						<td>Disease <div class="edit"></div></td>
						<td>:</td>
						<td id=disease><b>${requestScope.Exam.disease}</b></td>
					</tr>

				</table>

			</td>
		</tr>
	</table>
</div>

<div id=main style="display: block;">


<div style="width: 450px; float: left; margin-right: 20px">
<h2>Labs Details</h2>
	<br />
	<p>
		<input type=button value="Add" onclick="LoadList('listSerAll')">
	</p>
	<br>
	<table class='jtable'>
		<thead>
			<tr>
				<th>Lab Service Name</th>
				<th>Description</th>
				<th>Result</th>
				<th>Action</th>
				

			</tr>
		</thead>
		<tbody id="listSerbyID">
			<c:forEach var="item" items="${requestScope.listLabs}">
				<tr>
					<td>${item.labServiceInfo.labSvName}</td>
					<td>${item.labServiceInfo.description}</td>
					<td>${item.result}</td>
					<td><div class=delete onclick="delLabs(${item.idLabServiceDetail})"></div></td>

				</tr>
			</c:forEach>

		</tbody>
	</table>
</div>
<div style="float: left;">

	<h2>Medicine Details</h2>
	<br />
	<p>
		<input type=button value="Add" onclick="LoadList('listMedAll')">
	</p>
	<br>
	<table class='jtable'>
		<thead>
			<tr>
				<th>Name</th>
				<th>Price</th>
				<th>Dose</th>
				<th>Quantity</th>
				<th>Actions</th>

			</tr>
		</thead>
		<tbody id="listMedbyID">
			<c:forEach var="item" items="${requestScope.listMeds}">
				<tr>
					<td>${item.medicineInfo.medicineName}</td>
					<td>${item.medicineInfo.price}</td>
					<td>${item.dose}</td>
					<td>${item.quantity}</td>
					<td><div class=delete onclick="delMeds(${item.idMedicineDetail})"></div></td>
				</tr>
			</c:forEach>

		</tbody>
	</table>


</div>

<div style="clear: both"></div>
</div>
	
<div id=listSerAll class=bound
	style="z-index: 999; position: absolute; left: 100px; top: 200px;">
	<h2>List Lab Service</h2>
	<br>
	<table class='jtable'>
		<thead>
			<tr>
				<th>Name</th>
				<th>Description</th>
				<th>Charges</th>
				<th>Actions</th>
			</tr>
		</thead>
		<tbody id="listSerAlltb">
			<tr>
				<td colspan=4 align=center><img
					src="/GoodHealth-web/css/Blue/images/loading42.gif" /></td>
			</tr>

		</tbody>

	</table>
	<br> <input type=button value=Done onclick="closeDiv('listSerAll')">
</div>



<div id=listMedAll class=bound
	style="z-index: 999; position: absolute; left: 100px; top: 200px;">
	<h2>List Medicine</h2>
	<br>
	<table class='jtable'>
		<thead>
			<tr>
				<th>Name</th>
				<th>Dose</th>
				<th>Quantity</th>
				<th>Actions</th>
			</tr>
		</thead>
		<tbody id="listMedAlltb">
			<tr>
				<td colspan=4 align=center><img
					src="/GoodHealth-web/css/Blue/images/loading42.gif" /></td>
			</tr>

		</tbody>

	</table>
	<br> <input type=button value=Done onclick="closeDiv('listMedAll')">
</div>
<%
	}
%>



